<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/photo_detail.css" />
<div id="photo-info">
    <img class="user-img" src="images/profile-photo.jpg" />
    <h2><?php echo $hinh->ten_hinh; ?></h2>
    <span class="detail">Hình được đăng bởi <a href="#" class="user-link"><?php echo $album->idThanhVien->ten_dang_nhap; ?></a> | Thuộc Album <a class="user-link" href="<?php echo Yii::app()->createUrl('site/viewAlbum', array('id' => $hinh->idAlbum->id)); ?>"><?php echo $album->ten_album; ?></a> | <?php echo count($hinh->binhLuanHinhs); ?> bình luận | <?php echo count($hinh->hinhLikes); ?> Thích</span>
    <span class="light-box">Xem bằng:&nbsp;<a href="index.php?r=site/Lightbox&id=<?php echo $album->id; ?>" class="light-box-link">Lightbox</a></span>
    <div class="detail">
        <?PHP 
        $HinhTag = HinhTag::model()->findAllByAttributes(array('id_hinh'=>$hinh->id));
        foreach($HinhTag as $row_HinhTag)
        {
            $TagObj = Tag::model()->findByPk($row_HinhTag['id_tag']);
            
            if($TagObj!=null) echo '<span class="button_tag"><a href="index.php?r=site/explore&key='.$TagObj->ten_tag.'" title="Tìm kiếm các ảnh có tag '.$TagObj->ten_tag.'">'.$TagObj->ten_tag.'</a></span>';
        }
        ?>
    </div>
</div>
<script type="text/javascript">
    $(function () {

        var $container = $('#album-thumbnails');

        $container.imagesLoaded(function () {
            $container.isotope({
                itemSelector: '.photo'
            });
        });
    });
</script>
<div id="image">
    
    <img id="main-image" src="server/php/files/<?php echo $hinh->id; ?>.jpeg" />
    <div class="image-info">
        <div id="navigator">
         <?PHP 
            $Like = HinhLike::model()->findAllByAttributes(array('id_hinh'=>$hinh->id));
            $checkLike = 0;
            if(isset(Yii::app()->user->id)) {
                $Likec = HinhLike::model()->findByAttributes(array('id_hinh'=>$hinh->id,'id_thanh_vien'=>Yii::app()->user->id));
                if($Likec == null) $checkLike = 1;            
            }
            $numberLike = count($Like);
         ?>
            
        <?PHP if(isset(Yii::app()->user->id)) { ?>
        <a class="button" href="#" <?PHP if($checkLike==1) echo 'onClick="like()"';  ?>  id="likebutton"><?PHP if($checkLike==1) echo 'Thích '; else echo '<font color="red">Đã thích </font>';  ?> <span class="like_num"><?PHP echo $numberLike; ?></span></a> 
        <?PHP } else {  ?>
        <a class="button" id="likebutton">Thích <span class="like_num"><?PHP echo $numberLike; ?></span></a> 
        <?PHP } ?>
        <a class="button"href="index.php?r=site/Lightbox&id=<?PHP echo $hinh->idAlbum->id; ?>">Lightbox</a>
        <a class="prev-photo <?php if($prev_index == -1) echo 'inactive'; ?>" <?php if($prev_index != -1) {echo 'href="' . Yii::app()->createUrl('site/viewphoto', array('id' => $prev_id)) . '"';} ?>><img src="images/prev.png" />Ảnh trước</a>
        <a class="next-photo <?php if($next_index == -1) echo 'inactive'; ?>" <?php if($next_index != -1) {echo 'href="' . Yii::app()->createUrl('site/viewphoto', array('id' => $next_id)) . '"';} ?>>Ảnh tiếp theo<img src="images/next.png" /></a>
    </div>
        <span class="image-descrip"><?php echo $hinh->mo_ta; ?>&nbsp;</span>
    </div>
</div>
<script>
            function like()
            {
                $.ajax({
                    type: "GET",
                    url: "index.php?r=site/AjaxLike",
                    data: { id: "<?PHP echo $hinh->id; ?>"}
                    }).done(function( msg ) {
                    //alert( "Data Saved: " + msg );
                    if(msg == "1") {
                        var like = parseInt($('.like_num').html());
                        like = like + 1;
                        var stringLike = "<font color=\"red\">Đã thích</font> <span class=\"like_num\">" + like + "</span>";
                        $('#likebutton').html(stringLike);                        
                    } else {
                        alert('Bạn không thể like một hình nhiều lần!');
                    }
                
                });
                
            }
</script>
<div id="album-thumbnails" class="nano photos">
    <?php
    $hinh_trong_album = new Hinh();
    $hinh_trong_album->id_album = $album->id;
    $this->widget('zii.widgets.CListView', array(
        'dataProvider' => $hinh_trong_album->search(),
        'itemView' => '_imageInAlbum',
        'template' => '{items}',
        'enablePagination' => false,
    ));
    ?>
</div>
<div id="comment">
    <h2>Bình luận</h2>
    <ul>
        <?php
        $this->widget('zii.widgets.CListView', array(
            'dataProvider' => $binh_luan->search(),
            'itemView' => '_albumCommentItem',
            'template' => '{items}',
            'emptyText' => '',
        ));
        ?>
    </ul>
    <div id="comment-form">


        <?php if(isset(Yii::app()->user->id)) { 
        $form = $this->beginWidget('CActiveForm', array(
            'id' => 'comment-fform',
            'enableAjaxValidation' => true,
            'enableClientValidation'=>true,
            ));
        ?>
        <img class="user-img" src="images/profile-photo.jpg" />
        <?php echo $form->textArea($binh_luan, 'noi_dung', array('placeholder' => 'Nhập nội dung bình luận')); ?>
        <?php echo CHtml::submitButton('Bình luận'); ?>
        <div class="clear"></div>


        <?php $this->endWidget();
        } else {
            echo "&nbsp;&nbsp;&nbsp;&nbsp;Bạn cần đăng nhập để bình luận!";            
        }
        ?>


    </div>
</div>
<div class="clear" />